/*
 * Copyright (C) 2022 Huawei Technologies Co., Ltd.
 * Licensed under the Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *     http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
 * PURPOSE.
 * See the Mulan PSL v2 for more details.
 */
#include <string.h>
#include <stdint.h>
#include <crypto_wrapper.h>

const uint8_t g_pub_ca_ecc_key[] = {
    0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x02, 0x01, 0x06, 0x08, 0x2A,
    0x86, 0x48, 0xCE, 0x3D, 0x03, 0x01, 0x07, 0x03, 0x42, 0x00, 0x04, 0xB4, 0x76, 0x8F, 0xD1, 0xA1,
    0x34, 0xC0, 0x5E, 0x99, 0xB5, 0xF1, 0x49, 0xA0, 0x3D, 0x83, 0x0B, 0xDF, 0x9E, 0x00, 0x6E, 0x64,
    0x56, 0xBB, 0xEE, 0x1B, 0xBE, 0xFB, 0x2E, 0x32, 0x2E, 0x16, 0x8F, 0x48, 0xBE, 0x76, 0x21, 0xBF,
    0xE3, 0xB0, 0x50, 0x77, 0x80, 0xA3, 0x4D, 0x34, 0x5C, 0xD1, 0xE1, 0x7C, 0x2A, 0x42, 0xD8, 0x2C,
    0x91, 0x63, 0x4B, 0xAD, 0x72, 0xB6, 0x56, 0xCE, 0xE6, 0x02, 0x4B
};

const uint8_t g_pub_ca_rsa_key[] = {
    0x30, 0x82, 0x02, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01,
    0x01, 0x05, 0x00, 0x03, 0x82, 0x02, 0x0f, 0x00, 0x30, 0x82, 0x02, 0x0a, 0x02, 0x82, 0x02, 0x01,
    0x00, 0xb7, 0xe5, 0xa2, 0x20, 0x0c, 0x8f, 0xaf, 0x3f, 0xca, 0xe4, 0xd2, 0x59, 0x74, 0xcb, 0x2e,
    0x60, 0xaa, 0x54, 0x18, 0xc0, 0x2b, 0x3d, 0x17, 0x15, 0x88, 0x28, 0x10, 0xd7, 0xd2, 0xb1, 0x11,
    0x99, 0xb8, 0x11, 0x9f, 0xf8, 0x66, 0x21, 0xf2, 0x7a, 0xff, 0x7c, 0x97, 0x04, 0x8b, 0x33, 0xc6,
    0x77, 0x3d, 0x42, 0x8b, 0x62, 0x09, 0x81, 0x63, 0xd2, 0xa7, 0x26, 0xc0, 0xd8, 0xff, 0x77, 0x56,
    0x9c, 0xf4, 0xea, 0x4b, 0x64, 0x50, 0x5a, 0xa4, 0x3c, 0x1f, 0x62, 0x28, 0x82, 0x70, 0xa9, 0x5b,
    0xf3, 0x6b, 0x2f, 0x95, 0xcd, 0xec, 0xa8, 0x21, 0x33, 0x88, 0x48, 0xfc, 0x72, 0x53, 0x74, 0x29,
    0x7e, 0x6c, 0x0b, 0xd9, 0x6b, 0x8b, 0xcf, 0x40, 0x8d, 0xd2, 0xae, 0x73, 0x1c, 0xdd, 0xd0, 0xe0,
    0x63, 0xf4, 0x6c, 0xe0, 0xa4, 0x68, 0x41, 0x81, 0x1d, 0x9a, 0xbb, 0x80, 0x87, 0x25, 0x94, 0x84,
    0x6c, 0xee, 0x82, 0xcd, 0x39, 0xcc, 0x07, 0xde, 0xe7, 0x99, 0x93, 0x49, 0x60, 0x3d, 0xdf, 0x61,
    0x23, 0x22, 0xa1, 0xe7, 0x02, 0x56, 0xe0, 0xde, 0x52, 0x4c, 0x69, 0x37, 0x50, 0x4b, 0xc6, 0xf8,
    0xab, 0x85, 0x54, 0xc4, 0x73, 0x3a, 0xf6, 0xa5, 0xde, 0xf5, 0x7e, 0x77, 0x7c, 0x43, 0xac, 0x2f,
    0x0e, 0x61, 0x2b, 0x35, 0x59, 0xd1, 0xa1, 0xe2, 0xe9, 0xbf, 0x12, 0x90, 0xdd, 0x10, 0xf4, 0x06,
    0xd3, 0xa3, 0x57, 0x03, 0x87, 0x94, 0xf3, 0xc5, 0xde, 0xa8, 0x44, 0xf8, 0x14, 0x61, 0x2a, 0xb3,
    0xa5, 0x87, 0xf7, 0x80, 0x9a, 0x89, 0x85, 0x1d, 0x48, 0x32, 0x83, 0xd2, 0x77, 0xca, 0x1e, 0xf2,
    0x5f, 0xa8, 0xc7, 0x22, 0xee, 0x05, 0x82, 0xec, 0xe7, 0x57, 0x50, 0xc1, 0x13, 0x69, 0x73, 0x3a,
    0xb0, 0xf9, 0xee, 0x54, 0x0c, 0xcc, 0x4d, 0x00, 0xa6, 0xcb, 0x39, 0x02, 0xa8, 0x1b, 0x46, 0xaa,
    0xf4, 0x99, 0xba, 0xff, 0xd1, 0xd3, 0xd5, 0x64, 0x78, 0x5d, 0x9e, 0x57, 0x10, 0x93, 0xad, 0xbf,
    0xd0, 0x88, 0x54, 0xd4, 0xd3, 0x1a, 0x3f, 0x8d, 0xf1, 0x8b, 0xf6, 0x58, 0x57, 0xc8, 0x5b, 0xd3,
    0xc6, 0x56, 0x97, 0x6c, 0x14, 0xdd, 0x66, 0x9f, 0xef, 0x07, 0x2b, 0x2d, 0xe4, 0x47, 0x60, 0xd5,
    0xb1, 0xa9, 0xe4, 0xa1, 0xa7, 0xff, 0x24, 0xb0, 0x6d, 0x86, 0x52, 0x3b, 0xe8, 0x2a, 0xbe, 0x37,
    0x3f, 0x18, 0xf8, 0xe2, 0x5f, 0xb2, 0x94, 0xe9, 0x8d, 0x10, 0x66, 0x39, 0x4b, 0x71, 0x70, 0x41,
    0x4b, 0xed, 0xe5, 0x6c, 0x56, 0xc5, 0x99, 0x9e, 0xb2, 0xb3, 0x25, 0x26, 0xf5, 0xc4, 0xae, 0x84,
    0x2d, 0x32, 0x0d, 0x14, 0xeb, 0x0f, 0x1d, 0x01, 0x6b, 0x65, 0x63, 0x2a, 0xeb, 0x6a, 0xd1, 0xe8,
    0x03, 0x28, 0xc0, 0xf6, 0x6f, 0x2b, 0xd8, 0xe9, 0x97, 0xb6, 0xee, 0xf7, 0x42, 0x0d, 0x03, 0xc9,
    0x86, 0xa5, 0x00, 0x25, 0x72, 0x70, 0x35, 0x05, 0xda, 0xc1, 0xad, 0xab, 0x1b, 0x26, 0x68, 0xd6,
    0xbe, 0xdf, 0xa2, 0x73, 0x51, 0x06, 0x6f, 0x08, 0xa4, 0x79, 0xa7, 0xd2, 0x2a, 0xeb, 0x25, 0x64,
    0x1f, 0x74, 0xd9, 0x56, 0x53, 0xa5, 0x2c, 0xb1, 0x18, 0xf6, 0xd2, 0xd1, 0xc7, 0x6f, 0xed, 0xa6,
    0x1b, 0x80, 0x9d, 0xc6, 0x1b, 0xb5, 0xcc, 0x17, 0x62, 0x76, 0x79, 0x4f, 0xa6, 0x7e, 0x58, 0xf8,
    0xbe, 0x71, 0x89, 0xc4, 0xbd, 0x12, 0xf8, 0xbd, 0x99, 0x7f, 0x2b, 0xa8, 0x95, 0x3e, 0xbe, 0xfa,
    0xf5, 0x93, 0x5c, 0x1b, 0x04, 0x90, 0xb0, 0x66, 0xa3, 0xf6, 0x53, 0xb8, 0x88, 0x25, 0x4d, 0xf4,
    0x31, 0x3c, 0x62, 0x6a, 0x10, 0x19, 0x0b, 0x72, 0x69, 0x5f, 0xb2, 0x55, 0xcd, 0x3a, 0xc3, 0xf0,
    0xcf, 0xc2, 0x16, 0xcf, 0xb6, 0x8f, 0x62, 0x06, 0xf4, 0x8b, 0xec, 0x00, 0x19, 0x1d, 0x42, 0x8c,
    0xa7, 0x02, 0x03, 0x01, 0x00, 0x01
};

const uint8_t g_priv_ca_ecc_key[] = {
    0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x02, 0x01, 0x06, 0x08, 0x2A,
    0x86, 0x48, 0xCE, 0x3D, 0x03, 0x01, 0x07, 0x03, 0x42, 0x00, 0x04, 0x30, 0xF5, 0xA0, 0xBF, 0xAC,
    0x87, 0x56, 0xFE, 0x53, 0xF1, 0x31, 0xF1, 0x52, 0x60, 0xB6, 0x1C, 0xB5, 0xF3, 0x19, 0x18, 0x2D,
    0x07, 0x39, 0xF3, 0xDB, 0x97, 0x40, 0xFF, 0xC0, 0x2F, 0x80, 0x43, 0x53, 0x24, 0x01, 0x7E, 0x64,
    0x35, 0xED, 0x97, 0x46, 0x33, 0xE4, 0xD6, 0x28, 0x8E, 0x1F, 0x1A, 0x07, 0x84, 0x54, 0xCC, 0xCA,
    0x65, 0x2B, 0x48, 0x95, 0x40, 0x90, 0x75, 0x9E, 0x74, 0x75, 0x27
};

const uint8_t g_priv_ca_rsa_key[] = {
    0x30, 0x82, 0x02, 0x22, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01,
    0x01, 0x05, 0x00, 0x03, 0x82, 0x02, 0x0F, 0x00, 0x30, 0x82, 0x02, 0x0A, 0x02, 0x82, 0x02, 0x01,
    0x00, 0xBF, 0xE1, 0xFB, 0x8B, 0xB6, 0xA0, 0x6F, 0xE3, 0xA4, 0x15, 0x4A, 0x07, 0x7B, 0xEF, 0xCC,
    0x02, 0x6F, 0x05, 0x5F, 0x6C, 0x08, 0xDA, 0xF4, 0xA5, 0x89, 0x14, 0x9D, 0xEF, 0xFF, 0x06, 0x9B,
    0x04, 0x5A, 0xA4, 0xE6, 0x0C, 0x2C, 0x63, 0x9B, 0xAC, 0x9B, 0xDE, 0x35, 0xC3, 0x3E, 0xD7, 0x47,
    0xBC, 0x6D, 0xD5, 0x85, 0x07, 0xCE, 0x9A, 0x51, 0x45, 0xA0, 0x5C, 0x44, 0xCE, 0xC8, 0x1E, 0xED,
    0x55, 0x95, 0xBA, 0xBA, 0xAE, 0x17, 0x9B, 0xB6, 0x23, 0x50, 0xB8, 0x97, 0x65, 0x12, 0x52, 0xE3,
    0x58, 0xD2, 0x46, 0x54, 0x75, 0xF7, 0xC8, 0x7C, 0x99, 0xA9, 0x1B, 0x34, 0x6D, 0xE2, 0x40, 0xA2,
    0x92, 0x98, 0x52, 0x47, 0xBD, 0xC5, 0xA0, 0x18, 0x5D, 0xB7, 0xFF, 0xE4, 0xF8, 0x9F, 0x44, 0x64,
    0x06, 0xAA, 0x9D, 0x69, 0x4B, 0xD5, 0x60, 0x03, 0x7E, 0x02, 0x0E, 0x1C, 0x83, 0xAD, 0x89, 0x2A,
    0x8F, 0x2A, 0x41, 0xAC, 0xF5, 0x46, 0x11, 0x18, 0x02, 0xFA, 0xC6, 0xC6, 0xF5, 0xC3, 0x5A, 0x05,
    0x9A, 0x84, 0x2A, 0xF6, 0x1E, 0xD5, 0x48, 0x86, 0xA0, 0x85, 0x75, 0xCA, 0xD0, 0xD4, 0xA7, 0xA5,
    0x8D, 0x62, 0xD5, 0xAB, 0x91, 0xC0, 0x3B, 0x96, 0xBD, 0xC8, 0x4C, 0x8C, 0xFA, 0xAB, 0xDE, 0x39,
    0xD6, 0x92, 0x70, 0xCE, 0x23, 0x15, 0xC3, 0xED, 0x5D, 0xF7, 0x9B, 0x85, 0x10, 0x46, 0x2B, 0x18,
    0xBE, 0x92, 0x52, 0x4D, 0x2E, 0x4F, 0xF5, 0x17, 0x80, 0x81, 0xBC, 0x54, 0xDA, 0x52, 0xA6, 0xB3,
    0xD4, 0x5C, 0x41, 0xBA, 0x99, 0x1D, 0x87, 0x82, 0xA5, 0xBC, 0x01, 0x49, 0x83, 0x77, 0x09, 0xA0,
    0x6D, 0x13, 0xD0, 0xBA, 0x51, 0x84, 0xA6, 0xDD, 0xA1, 0xD3, 0xB3, 0x81, 0xB7, 0x2B, 0xBA, 0x8E,
    0xFC, 0x7F, 0xDC, 0x08, 0xC7, 0xC0, 0xCC, 0x07, 0x77, 0x1C, 0x3A, 0x2F, 0x5C, 0x2B, 0x83, 0xF2,
    0x1C, 0xA5, 0x0E, 0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C, 0x89, 0x4F, 0x5D, 0xD1, 0x0E, 0xE8, 0x90, 0x05,
    0x55, 0xA9, 0x3C, 0x21, 0x0C, 0xF5, 0xCC, 0xD2, 0x6C, 0xC0, 0x02, 0xFA, 0x75, 0xB6, 0xBA, 0x96,
    0x4C, 0x67, 0xD6, 0xB0, 0xB6, 0xFF, 0x17, 0x9F, 0x29, 0xE8, 0x8C, 0x77, 0xD2, 0x8D, 0xCD, 0x2B,
    0xEA, 0x00, 0xBD, 0x2D, 0x17, 0x80, 0x85, 0xB9, 0xB6, 0xB1, 0x06, 0x22, 0x60, 0xA6, 0x46, 0xF3,
    0x86, 0xF4, 0x9C, 0xC8, 0x3C, 0x9A, 0x8E, 0x24, 0xC2, 0x2F, 0x70, 0x65, 0x2A, 0xD3, 0x12, 0x5E,
    0x11, 0x02, 0x03, 0x01, 0x00, 0x01
};

const rsa_pub_key_t *get_config_pub_key(void)
{
    return NULL;
}

uint32_t get_ca_pubkey_size(void)
{
    return 0;
}

const uint8_t *get_ca_pubkey(void)
{
    return NULL;
}

#define ALG_ECDSA 3
uint32_t get_pub_ca_key_size(uint32_t alg)
{
    if (alg == ALG_ECDSA)
        return sizeof(g_pub_ca_ecc_key);
    else
        return sizeof(g_pub_ca_rsa_key);
}

const uint8_t *get_pub_ca_key(uint32_t alg)
{
    if (alg == ALG_ECDSA)
        return g_pub_ca_ecc_key;
    else
        return g_pub_ca_rsa_key;
}

uint32_t get_priv_ca_key_size(uint32_t alg)
{
    if (alg == ALG_ECDSA)
        return sizeof(g_priv_ca_ecc_key);
    else
        return sizeof(g_priv_ca_rsa_key);
}

const uint8_t *get_priv_ca_key(uint32_t alg)
{
    if (alg == ALG_ECDSA)
        return g_priv_ca_ecc_key;
    else
        return g_priv_ca_rsa_key;
}